//#include <stdio.h>
//#include <stdlib.h>
//#include <stdbool.h>
//
//int main()
//{
//    int m;
//    scanf_s("%d", &m); 
//
//    int* arr = (int*)malloc(m * sizeof(int));
//    for (int i = 0; i < m; i++)
//    {
//        scanf_s("%d", &arr[i]); 
//    }
//
//    int n;
//    scanf_s("%d", &n); 
//
//    if (n == 0) 
//    {
//        printf("true\n");
//        free(arr);
//        return 0;
//    }
//
//    long long total_max_ones = 0; 
//    int i = 0;
//
//    while (i < m) {
//        if (arr[i] == 0) 
//        {
//            int start = i;
//            while (i < m && arr[i] == 0)
//            {
//                i++;
//            }
//            int end = i - 1;
//            int L = end - start + 1; 
//
//            int left_restricted = (start > 0) ? (arr[start - 1] == 1) : 0;
//            int right_restricted = (end < m - 1) ? (arr[end + 1] == 1) : 0;
//
//            int available = L;
//            if (left_restricted) available--;
//            if (right_restricted) available--;
//            if (available < 0) available = 0; 
//
//            total_max_ones += (available + 1) / 2;
//        }
//        else 
//        {
//            i++; 
//        }
//    }
//
//    if (n <= total_max_ones) 
//    {
//        printf("true\n");
//    }
//    else
//    {
//        printf("false\n");
//    }
//    free(arr);
//    return 0;
//}

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int pos;  
    int count; 
} Candidate;

int cmp_candidate(const void* a, const void* b)
{
    const Candidate* ca = (const Candidate*)a;
    const Candidate* cb = (const Candidate*)b;
    if (cb->count != ca->count)
    {
        return cb->count - ca->count; 
    }
    return ca->pos - cb->pos; 
}

int cmp_pos(const void* a, const void* b)
{
    return *(const int*)a - *(const int*)b;
}

int main()
{
    int n, m, k, l, d;
    scanf_s("%d %d %d %d %d", &n, &m, &k, &l, &d);

    int* row_value = (int*)calloc(n + 1, sizeof(int));
    int* col_value = (int*)calloc(m + 1, sizeof(int));

    for (int i = 0; i < d; i++) 
    {
        int x1, y1, x2, y2;
        scanf_s("%d %d %d %d", &x1, &y1, &x2, &y2);

        if (x1 == x2)
        { 
            int min_col = (y1 < y2) ? y1 : y2;
            col_value[min_col]++;
        }
        else if (y1 == y2) 
        { 
            int min_row = (x1 < x2) ? x1 : x2;
            row_value[min_row]++;
        }
    }

    Candidate* row_candidates = (Candidate*)malloc((n - 1) * sizeof(Candidate));
    for (int i = 1; i < n; i++) 
    {
        row_candidates[i - 1].pos = i;
        row_candidates[i - 1].count = row_value[i];
    }

    Candidate* col_candidates = (Candidate*)malloc((m - 1) * sizeof(Candidate));
    for (int j = 1; j < m; j++)
    {
        col_candidates[j - 1].pos = j;
        col_candidates[j - 1].count = col_value[j];
    }

    qsort(row_candidates, n - 1, sizeof(Candidate), cmp_candidate);
    qsort(col_candidates, m - 1, sizeof(Candidate), cmp_candidate);

    int* selected_rows = (int*)malloc(k * sizeof(int));
    for (int i = 0; i < k; i++) 
    {
        selected_rows[i] = row_candidates[i].pos;
    }

    int* selected_cols = (int*)malloc(l * sizeof(int));
    for (int i = 0; i < l; i++)
    {
        selected_cols[i] = col_candidates[i].pos;
    }

    qsort(selected_rows, k, sizeof(int), cmp_pos);
    qsort(selected_cols, l, sizeof(int), cmp_pos);

    for (int i = 0; i < k; i++) 
    {
        printf("%d", selected_rows[i]);
        if (i < k - 1) printf(" ");
    }
    printf("\n");

    for (int i = 0; i < l; i++)
    {
        printf("%d", selected_cols[i]);
        if (i < l - 1) printf(" ");
    }
    printf("\n");

    free(row_value);
    free(col_value);
    free(row_candidates);
    free(col_candidates);
    free(selected_rows);
    free(selected_cols);

    return 0;
}